package zilvic.game;

import java.util.ArrayList;
import java.util.Arrays;
import zilvic.game.character.inventory.Item;
import zilvic.game.character.skilltree.Skill;
import zilvic.game.room.Room;
import zilvic.game.room.entity.actor.Actor;
import zilvic.game.room.entity.effect.Effect;
import zilvic.game.room.entity.trigger.Timer;
import zilvic.game.room.entity.trigger.Trigger;
import zilvic.resources.ByteMagic;
import zilvic.resources.Parsable;

/**
 *
 * @author Duncan
 */
public class GameLibrary implements Parsable {
    private ArrayList<Item> items       = new ArrayList<Item>();
    private ArrayList<Actor> actors     = new ArrayList<Actor>();
    private ArrayList<Skill> skills     = new ArrayList<Skill>();
    private ArrayList<Effect> effects   = new ArrayList<Effect>();
    private ArrayList<Trigger> triggers = new ArrayList<Trigger>();
    private ArrayList<Timer> timers     = new ArrayList<Timer>();
    private ArrayList<Room> rooms       = new ArrayList<Room>();

    public void addItem(Item item) {
        items.add(item);
    }

    public void addActor(Actor actor) {
        actors.add(actor);
    }

    public void addSkill(Skill skill) {
        skills.add(skill);
    }

    public void addEffect(Effect effect) {
        effects.add(effect);
    }

    public void addTrigger(Trigger trigger) {
        triggers.add(trigger);
    }

    public void addTimer(Timer timer) {
        timers.add(timer);
    }

    public void addRoom(Room room) {
        rooms.add(room);
    }

    public void removeItem(Item item) {
        items.remove(item);
    }

    public void removeActor(Actor actor) {
        actors.remove(actor);
    }

    public void removeSkill(Skill skill) {
        skills.remove(skill);
    }

    public void removeEffect(Effect effect) {
        effects.remove(effect);
    }

    public void removeTrigger(Trigger trigger) {
        triggers.remove(trigger);
    }

    public void removeTimer(Timer timer) {
        timers.remove(timer);
    }

    public void removeRoom(Room room) {
        rooms.remove(room);
    }

    public int itemCount() {
        return items.size();
    }

    public int actorCount() {
        return actors.size();
    }

    public int skillCount() {
        return skills.size();
    }

    public int effectCount() {
        return effects.size();
    }

    public int triggerCount() {
        return triggers.size();
    }

    public int timerCount() {
        return timers.size();
    }

    public int roomCount() {
        return rooms.size();
    }

    public Item getItem(int index) {
        return items.get(index);
    }

    public Actor getActor(int index) {
        return actors.get(index);
    }

    public Skill getSkill(int index) {
        return skills.get(index);
    }

    public Effect getEffect(int index) {
        return effects.get(index);
    }

    public Trigger getTrigger(int index) {
        return triggers.get(index);
    }

    public Timer getTimer(int index) {
        return timers.get(index);
    }

    public Room getRoom(int index) {
        return rooms.get(index);
    }

    public byte[] toBytes() {
        return ByteMagic.compressBytes(new byte[][] {
            ByteMagic.parsablesToBytes((Item[]) items.toArray()),
            ByteMagic.parsablesToBytes((Actor[]) actors.toArray()),
            ByteMagic.parsablesToBytes((Skill[]) skills.toArray()),
            ByteMagic.parsablesToBytes((Effect[]) effects.toArray()),
            ByteMagic.parsablesToBytes((Trigger[]) triggers.toArray()),
            ByteMagic.parsablesToBytes((Timer[]) timers.toArray()),
            ByteMagic.parsablesToBytes((Room[]) rooms.toArray())});
    }

    public void fromBytes(byte[] bytes) {
        byte[][] u = ByteMagic.uncompressBytes(bytes);
        items    = new ArrayList<Item>(Arrays.asList((Item[]) ByteMagic.bytesToParsables(u[0])));
        actors   = new ArrayList<Actor>(Arrays.asList((Actor[]) ByteMagic.bytesToParsables(u[1])));
        skills   = new ArrayList<Skill>(Arrays.asList((Skill[]) ByteMagic.bytesToParsables(u[2])));
        effects  = new ArrayList<Effect>(Arrays.asList((Effect[]) ByteMagic.bytesToParsables(u[3])));
        triggers = new ArrayList<Trigger>(Arrays.asList((Trigger[]) ByteMagic.bytesToParsables(u[4])));
        timers   = new ArrayList<Timer>(Arrays.asList((Timer[]) ByteMagic.bytesToParsables(u[5])));
        rooms    = new ArrayList<Room>(Arrays.asList((Room[]) ByteMagic.bytesToParsables(u[6])));
    }
}